<?php
namespace Admin\Controller;

class IndexController extends \Think\Controller{

    public function index(){
		//判断是否登录
		
        $customer = session(C('ADMIN_SESSION'));
        if(empty($customer)) $this->redirect('Admin/Index/login');
        $contentUrl = U('Goods/index');
        $this->assign('contentUrl', $contentUrl);
        $this->display();
    }
	
    public function login(){
        if(session(C('ADMIN_SESSION'))){
            $this->redirect("Admin/Index/index");
        }else{
            $this->display();            
        }
    }
	
    //执行登陆
    public function signIn(){
		$name = I("post.name","","trim");
		$pass = I("post.pass","","trim");
		if(empty($name) || empty($pass)) $this->error('用户名或者密码不能为空，请重新输入');
	        
		if($customer = M('Customer')->where(array('username'=>$name,'password'=>md5($pass)))->find()){
        if($customer['status'] == '2') $this->error('您的账号已被系统关闭');
            session(C('ADMIN_SESSION'),$customer);
            $this->success('登录成功！自动跳转中...',U('Index/index'));
        }else{
            $this->error('用户名或密码错误!');
        }
    }
	//退出操作
    public function logout(){
        session(C('ADMIN_SESSION'),null);
        session(C('OVER_ADMINER'),null);
        $this->redirect('Admin/Index/login');
    }
}
